/*
 * ComparTable.c
 *
 *  Created on: 03/05/2013
 *      Author: pargo
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>

typedef struct _tab{
	char name[50];
	float vl[3];
}tab;

char headers[3][50];

tab table[100];


int main(int arg, char* argvs[]){

	char* filedefname = argvs[1];
	char* filein1name = argvs[2];
	char* filein2name = argvs[2];
	char* fileoutname = argvs[3];

	FILE* def = fopen(filedefname, "r");
	FILE* input1 = fopen(filein1name, "r");
	FILE* input2 = fopen(filein2name, "r");
	FILE* output = fopen(fileoutname, "w");

	for(long i = 0; i < 3; i++){
		fscanf(def, "%s", &headers[i]);
		printf(output,"%s \t", headers[i]);
	}
	printf(output," \n");


	char name[50];
	double vl;
	long v = 0;

	while(!feof(input1)){
		fscanf(input1, "%s", &name);
		fscanf(input1, "%lu", &vl);

		if(strcmp(table[v].name, name))
			v++;

		strcpy(table[v].name, name);
		table[v].vl[0] = vl;
	}

	long u;
	while(!feof(input2)){
		fscanf(input2, "%s", &name);
		fscanf(input2, "%lu", &vl);
		u = 0;
		while(strcmp(table[u].name, name))
			u++;

		strcpy(table[u].name, name);
		table[u].vl[1] = vl;
	}


	for(long i = 0; i <= v; i++)table[i].vl[2] = table[i].vl[0]/table[i].vl[1];

	for(long i = 1; i <= v; i++){
		printf(output, "%s", table[i].name);
		for(long j = 0; j < 3; j++)printf(output, "\t %f", table[i].vl[j]);
		printf(output, "\n");
	}

	return 0;
}
